<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('订单详情列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>美食：</label>
                            <input type="text" name="foodId"/>
                        </li>
                        <li>
                            <label>名称：</label>
                            <input type="text" name="foodName"/>
                        </li>
                        <li>
                            <label>数量：</label>
                            <input type="text" name="foodNumber"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary multiple disabled" onclick="toSaveAll()"
               shiro:hasPermission="dc:orderDetail:edit">
                <i class="fa fa-edit"></i> 结算
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('dc:orderDetail:edit')}]];
    var removeFlag = [[${@permission.hasPermi('dc:orderDetail:remove')}]];
    var prefix = ctx + "dc/orderDetail";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "订单详情",
            columns: [{
                checkbox: true
            },
                {
                    field: 'carId',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'foodId',
                    title: '美食',
                    visible: false
                },
                {
                    field: 'foodName',
                    title: '名称'
                },
                {
                    field: 'foodNumber',
                    title: '数量'
                },
                {
                    field: 'foodPrice',
                    title: '单价(元/份)'
                },
                {
                    field: 'foodTotalPrice',
                    title: '总价',
                    formatter: function (value, row, index) {
                        return row.foodPrice * row.foodNumber + " 元";
                    }
                },
                {
                    field: 'orderId',
                    title: '订单',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.carId + '\')"><i class="fa fa-edit"></i>结算</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.carId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 计算
    function toSaveAll() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要结算选中的" + rows.length + "条数据吗?", function () {
            var url = table.options.removeUrl;
            var data = {"ids": rows.join()};
            /* $.operate.submit( prefix + "/jieSuan", "post", "json", data);*/
            $.modal.open('结算', prefix + "/jieSuan?ids=" + rows.join(), '900', '800');
        });
    }
</script>
</body>
</html>